import random
import numpy as np


def simulate_stun(attack_per_second, stun_probability, stun_duration, simulation_time, num_simulations):
    total_stun_durations = []

    for _ in range(num_simulations):
        current_time = 0
        stunned_until = -1
        total_stunned_time = 0

        while current_time < simulation_time:
            for _ in range(attack_per_second):
                if current_time >= stunned_until and random.random() < stun_probability:
                    stunned_until = current_time + stun_duration
                    total_stunned_time += stun_duration

                current_time += 1 / attack_per_second
                if current_time >= simulation_time:
                    break

        total_stun_durations.append(total_stunned_time)

    return total_stun_durations

# Parameters
attack_per_second = 3
stun_probability = 0.1
stun_duration = 2
simulation_time = 10
num_simulations = 1000

# Run simulations
stun_durations = simulate_stun(attack_per_second, stun_probability, stun_duration, simulation_time, num_simulations)

# Calculate expected stun duration
expected_stun_duration = np.mean(stun_durations)
print(f"Expected continuous stun duration over {num_simulations} simulations: {expected_stun_duration:.2f} seconds")
